<script setup>
import { ref, onMounted } from 'vue'
import { useRouter, useRoute } from 'vue-router'
import { Document, Warning, Calendar, List } from '@element-plus/icons-vue'

const router = useRouter()
const route = useRoute()
const activeMenu = ref('')

// 处理下拉菜单命令
const handleCommand = (command) => {
  // 根据命令跳转到对应页面
  switch (command) {
    case 'info':
      router.push('/stocktaking/info')
      break
    case 'loss':
      router.push('/stocktaking/loss')
      break
    case 'task':
      router.push('/stocktaking/task')
      break
    case 'taskdetails':
      router.push('/stocktaking/taskdetails')
      break
    default:
      break
  }
}

onMounted(() => {
  // 根据当前路由设置激活菜单
  if (route.path.includes('info')) {
    activeMenu.value = 'info'
  } else if (route.path.includes('loss')) {
    activeMenu.value = 'loss'
  } else if (route.path.includes('task')) {
    activeMenu.value = 'task'
  } else if (route.path.includes('taskdetails')) {
    activeMenu.value = 'taskdetails'
  }
})
</script>

<template>
  <div class="stocktaking-layout">
    <el-container>
      <!-- 头部区域 -->
      <el-header class="header-container">
        <div class="header-content">
          <h1 class="title">库存盘点管理系统</h1>

          <!-- 右侧菜单 -->
          <div class="right-menu">
            <el-dropdown @command="handleCommand">
              <span class="el-dropdown-link">
                <el-button type="primary" size="small">
                  <el-icon>
                    <Document />
                  </el-icon>
                  盘点信息
                </el-button>
              </span>
              <template #dropdown>
                <el-dropdown-menu>
                  <el-dropdown-item command="info">盘点信息</el-dropdown-item>
                  <el-dropdown-item command="loss">报损记录</el-dropdown-item>
                  <el-dropdown-item command="task">盘点任务</el-dropdown-item>
                  <el-dropdown-item command="taskdetails">任务详情</el-dropdown-item>
                </el-dropdown-menu>
              </template>
            </el-dropdown>
          </div>
        </div>
      </el-header>

      <!-- 主内容区域 -->
      <el-container class="main-container">
        <el-main class="main-content">
          <router-view v-if="$route.path !== '/stocktaking'" />
          <div v-else>
            <el-alert title="请选择左侧菜单查看具体内容" type="info" show-icon :closable="false" />
          </div>
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>

<style scoped>
.stocktaking-layout {
  height: 100%;
  background-color: #f5f7fa;
}

.header-container {
  background-color: #fff;
  color: #333;
  border-bottom: 1px solid #eee;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
  position: relative;
}

.header-content {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 40px;
  max-width: 1200px;
  margin: 0 auto;
  position: relative;
}

.title {
  font-size: 28px;
  font-weight: bold;
  color: #333;
  margin: 0;
  flex: 1;
  text-align: center;
}

.right-menu {
  position: absolute;
  right: 40px;
  top: 50%;
  transform: translateY(-50%);
  z-index: 100;
}

.el-dropdown-link {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
}

.el-dropdown-link .el-icon {
  font-size: 16px;
}

.main-container {
  padding: 20px;
}

.main-content {
  background-color: #fff;
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  padding: 20px;
  min-height: calc(100vh - 120px);
}

/* 响应式设计 */
@media (max-width: 1200px) {
  .header-content {
    flex-direction: column;
    align-items: center;
    padding: 20px;
  }

  .title {
    margin-bottom: 20px;
    text-align: center;
  }

  .right-menu {
    position: static;
    transform: none;
    top: auto;
    right: auto;
    margin-top: 10px;
  }
}
</style>